<% @page_title = "照片分享 | 多背一公斤 - 灾后学校重建计划" %>

<% content_for(:sidebar) do %>
  <% if @photo.school -%>
    <h2><%= link_to "回到#{@photo.school.title}", school_url(@photo.school.id) %></h2>
  <% end -%>
  <% if @photo.event -%>
    <h2><%= link_to "回到#{@photo.event.title}", event_url(@photo.event.id) %></h2>
  <% end -%>
<% end %>

<h1><%= @photo.title %></h1>
<p><span class="tip">由</span> <%= link_to @photo.user.login, user_path(@photo.user.id) %> <span class="tip">分享于 <%= show_date @photo.created_at %></span></p>
<% if @photo.event -%>
  <p>这张照片分享到了 <%= link_to @photo.event.title, event_path(@photo.event.id) %> 活动中</p>
<% end -%>
<% if @photo.school -%>
  <p>这张照片拍摄于 <%= link_to @photo.school.title, school_path(@photo.school.id) %></p>
<% end -%>
<p><%= image_tag @photo.public_filename(:medium) %></p>
<p><%= simple_format @photo.description %></p>

<% if @photo.editable_by?(current_user) -%>
  <p style="text-align:right;">操作: <%= link_to "编辑照片信息", edit_photo_url(@photo) %>, <%= link_to "删除", photo_url(@photo), :method => 'delete', :confirm => "确定要删除么？" %></p>
<% end -%>

<h2>用户留言 &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp; &middot;&nbsp;</h2>
<% @comments.each do |cmt| -%>
  <div class="cmt-item" style="margin-bottom:10px">
    <div style="float:left;margin:0 8px 0 0">
      <%= avatar_for cmt.user, "large" %><br />
    </div>
    <div style="margin-left:50px">
      <div>
        <div style="background-color:#ffc"><h2><%= h cmt.title %></h2></div>
        
        <% if cmt.editable_by?(current_user) -%>
        <span style="float:right">
          <%= link_to "修改", photo_edit_comment_path(@photo, cmt) %>
          <%= link_to "删除", photo_comment_path(@photo, cmt), :method => 'delete', :confirm => "您确定要删除么？" %>
        </span>
        <% end -%>
        
        <%= link_to cmt.user.login, user_path(cmt.user) %><span class="tip"> 写于 <%= show_datetime cmt.created_at %></span>
      </div>
      <div><%= cmt.content_html %></div>
    </div>
  </div>
<% end -%>
<hr />
<% if logged_in? -%>
  <% form_for :comment, :url => photo_comments_path(:photo_id => @photo.id) do |f| -%>
    <%= render :partial => 'photo_comments/form', :object => f, :locals => {:title => "Re:#{@photo.title}"} %>
    <p><%= submit_tag "发布评论" %></p>
  <% end -%>
<% else -%>
  <%= link_to "登录", login_url %>后你也可以发表评论或留言
<% end -%>